﻿cmake_minimum_required(VERSION 3.10)
project(NDFrame LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
endif()

# 全局启用位置无关代码（适用于静态库被共享库引用）
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# 定义项目选项
option(BUILD_UDataFrame_LIBS "Build ZDataFrame static libraries" ON)
option(BUILD_UDataFrame_TEST "Build ZDataFrame static tests" ON)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)


if (APPLE)
    set(OpenCV_DIR "/opt/homebrew/opt/opencv/lib/cmake/opencv4")
    find_package(OpenCV 4 REQUIRED CONFIG)
    message(STATUS "OpenCV 版本:    ${OpenCV_VERSION}")
    message(STATUS "OpenCV 包含目录: ${OpenCV_INCLUDE_DIRS}")
    message(STATUS "OpenCV 库:      ${OpenCV_LIBS}")

    list(APPEND EXTRA_INCLUDE_DIRS "/opt/homebrew/include")
endif()


# UDataFrame模块条件编译
if(BUILD_UDataFrame_LIBS)
    message("BUILD_UDataFrame_LIBS is ON")
    add_subdirectory(UDataFrame)
endif()
if(BUILD_UDataFrame_TEST)
    message("BUILD_UDataFrame_TEST is ON")
    add_subdirectory(UDataFrame_test)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    find_program(LSB_RELEASE_EXEC lsb_release)
    if(LSB_RELEASE_EXEC)
        execute_process(COMMAND ${LSB_RELEASE_EXEC} -is
                OUTPUT_VARIABLE LSB_RELEASE_ID
                OUTPUT_STRIP_TRAILING_WHITESPACE)
        message(STATUS "Linux distribution: ${LSB_RELEASE_ID}")
    endif()
elseif(APPLE)
    message(STATUS "Detected macOS platform")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
    message(STATUS "Detected Windows platform")
    add_definitions(-D_WIN32_WINNT=0x0A00)
endif()
